# -*- codeing = utf-8 -*-

# 给所有字段添加form-control属性
class BootStrap(object):
    bootstrap_class_exclude = []
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():  # name是字段名，field是CharField对象
            if name in self.bootstrap_class_exclude:
                continue
            old_class = field.widget.attrs.get('class','')  # 获取字段原有的属性
            # 在该字段原有属性的基础上再加一个form-control属性
            field.widget.attrs['class'] = '{} form-control'.format(old_class)
            field.widget.attrs['placeholder'] = '请输入{}'.format(field.label)